package uk.co.richardwkirk.parkrun.geo;

import uk.co.richardwkirk.parkrun.data.ParkrunDataLoadException;
import uk.co.richardwkirk.parkrun.web.ParkrunPageLoader;
import uk.co.richardwkirk.parkrun.web.ParkrunURLGenerator;

public class GeographicalData {

	public static String GEO_DATA_PATH = "wp-content/themes/parkrun/xml/geo.xml";
	
	/**
	 * Create a GeographicalData set from data loaded from the parkrun site.
	 * 
	 * @return a complete parkrun GeographicalData set
	 * @throws ParkrunDataLoadException
	 * @throws GeoDataException 
	 */
	public static Region loadParkrunWorld() throws ParkrunDataLoadException, GeoDataException {
		String geoDataPage = ParkrunURLGenerator.createUKSiteURL(GEO_DATA_PATH);
		return loadParkrunWorld(geoDataPage);
	}
	
	/**
	 * Create a GeographicalData set from data loaded from the specified
	 * file. The file could be local or remote.
	 * 
	 * @return a complete parkrun GeographicalData set
	 * @throws ParkrunDataLoadException
	 * @throws GeoDataException 
	 */
	public static Region loadParkrunWorld(String filename) throws ParkrunDataLoadException, GeoDataException {
		ParkrunPageLoader pageLoader = new ParkrunPageLoader();
		String fileContent = pageLoader.load(filename);
		GeoDataParser parser = new GeoDataParser(fileContent);
		return parser.createWorld();
	}
	
}